package com.loan.system.service.impl;

import com.loan.common.helper.LoginHelper;
import com.loan.common.utils.DateUtils;
import com.loan.system.domain.ApplyEntity;
import com.loan.system.domain.UserCompanyEntity;
import com.loan.system.mapper.UserCompanyMapper;
import com.loan.system.service.UserCompanyService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author shiguang on 2022/9/27 9:16
 */
@Service
@RequiredArgsConstructor
public class UserCompanyServiceImpl implements UserCompanyService {

    private final UserCompanyMapper userCompanyMapper;

    @Override
    public void save(ApplyEntity entity, Integer frozenDay) {
        UserCompanyEntity userCompanyEntity = new UserCompanyEntity();
        userCompanyEntity.setApplyId(entity.getId());
        userCompanyEntity.setUserId(entity.getUserId());
        userCompanyEntity.setCompanyId(entity.getCompanyId());
        userCompanyEntity.setStatus("1");
        userCompanyEntity.setFrozenDay(frozenDay);
        userCompanyEntity.setCreateTime(new Date());
        userCompanyEntity.setCreateBy(LoginHelper.getUsername());
        //计算什么时候解封
        userCompanyEntity.setThawDate(DateUtils.parseDateToStr("yyyy-MM-dd", DateUtils.addDays(new Date(), frozenDay)));
        userCompanyMapper.insert(userCompanyEntity);
    }
}
